package com.psm.controller;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Record;
import com.psm.interceptor.IndexInterceptor;
import com.psm.model.SysUser;
import com.psm.util.MD5;

@Before(IndexInterceptor.class)
public class PwdController extends BaseController{
	
	public void index() {
		setAttr("user_name",getCurrentUser().getStr("name"));
	}
	public void change(){
		String user_name=getCurrentUser().getStr("code");
        String user_pwd=this.getPara("userpwd");
        String user_npwd=this.getPara("usernpwd");
        String user_ntpwd=this.getPara("userntpwd");
        if("".equals(user_pwd)||"".equals(user_npwd)||"".equals(user_ntpwd)||!user_ntpwd.equals(user_npwd)){
        	this.rendJson_(0,"输入错误，请检查后操作！");
        }else{
	        Record user = SysUser.me.qryUser(user_name,user_pwd,"1");
	
	        if(null != user){
	        	String idString = user.getLong("id").toString();
	        	SysUser u = SysUser.me.findById(idString);
	        	u.set("pwd", MD5.getMD5ofStr(user_npwd));
	        	u.update();
	        	this.rendJson_(1, "操作成功");
	        }else{
	        	this.rendJson_(0,"原密码错误，请检查后操作！");
	        }
        }
	}

}
